<!DOCTYPE html>
<!--[if IE 9]>         <html class="no-js lt-ie10" lang="en"> <![endif]-->
<!--[if gt IE 9]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
    <meta charset="utf-8">

    <title>数字币对冲平台|BDS虚拟币对冲平台</title>
 		<#include "../static/top.ftl" >

</head>
<body>
<!-- Page Wrapper -->
<!-- In the PHP version you can set the following options from inc/config file -->
<!--
    Available classes:

    'page-loading'      enables page preloader
-->
<div id="page-wrapper" class="page-loading">
    <!-- Preloader -->
    <!-- Preloader functionality (initialized in js/app.js) - pageLoading() -->
    <!-- Used only if page preloader enabled from inc/config (PHP version) or the class 'page-loading' is added in #page-wrapper element (HTML version) -->
    <div class="preloader">
        <div class="inner">
            <!-- Animation spinner for all modern browsers -->
            <div class="preloader-spinner themed-background hidden-lt-ie10"></div>

            <!-- Text for IE9 -->
            <h3 class="text-primary visible-lt-ie10"><strong>Loading..</strong></h3>
        </div>
    </div>

    <div id="page-container" class="header-fixed-top sidebar-visible-lg-full sidebar-light">
        <!-- Alternative Sidebar -->

        <!-- END Alternative Sidebar -->

        <!-- Main Sidebar -->



                <#include "../static/menu.ftl" >


        <!-- END Main Sidebar -->

        <!-- Main Container -->
        <div id="main-container">
            <!-- Header -->
            <#include "../static/header.ftl" >
            <!-- END Header -->

            <!-- Page content -->
            <div id="page-content">
                <!-- Validation Header -->
                <div class="content-header">
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="header-section">
                                <h1>策略设置</h1>
                            </div>
                        </div>
                        <div class="col-sm-6 hidden-xs">
                            <div class="header-section">
                                <ul class="breadcrumb breadcrumb-top">
                                    <li>User Interface</li>
                                    <li>Forms</li>
                                    <li><a href="">Validation</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- END Validation Header -->

             
                 <!----------回购策略设置 -------------------->
                <div class="row">

                    <div class="col-md-12">
                        <!-- Form Validation Block -->
                        <div class="block">
                            <div class="block-title">
                                <h2>回购策略设置</h2>
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                    <form id="form-set-api" method="post" class="form-horizontal form-bordered">
                                        <div class="form-group">
                                            <div class="row">
                                                <div class="col-md-8">
                                                    <form id="form-set-api" method="post" class="form-horizontal form-bordered">
                                                        <div class="form-group">
                                                            <label class="col-md-3 control-label" for="access-key">上涨阀值</label>
                                                            <div class="col-md-6">
                                                                <input type="number" id="order_avg_price_threshold" name="order_avg_price_threshold" class="form-control buy_input" placeholder="" value="<#if args.order_avg_price_threshold??>${args.order_avg_price_threshold}<#else>0</#if>"/>
                                                            </div>
                                                            <label class="col-md-1 control-label quote_symbol">%</label>
                                                        </div>
                                                    </form>
                                                </div>
                                                <div class="col-md-4">
                                                    <span>当上涨超过历史交易记录价格平均值___%以上,则系统将不自动处理,发送危险交易通知提醒用户手动处理</span>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <!-- END Form Validation Block -->
                    </div>
                </div>
                 <!----------涨跌判定设置 -------------------->
                 <div class="row">
                        <div class="col-md-12">
                            <!-- Form Validation Block -->
                            <div class="block">
                                <div class="block-title">
                                    <h2>涨跌判定设置</h2>
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <form id="form-set-api" method="post" class="form-horizontal form-bordered">
                                            <div class="form-group">
                                                <div class="row">
                                                    <div class="col-md-8">
                                                        <form id="form-set-api" method="post" class="form-horizontal form-bordered">
                                                            <div class="form-group">
                                                                <label class="col-md-3 control-label" for="access-key">涨跌上界</label>
                                                                <div class="col-md-6">
                                                                    <input type="number" id="thld_start" name="thld_start" class="form-control buy_input" placeholder=""  value="<#if args.thld_start??>${args.thld_start}<#else>0</#if>">
                                                                </div>
                                                                <label class="col-md-1 control-label quote_symbol">%</label>
                                                            </div>
                                                            <div class="form-group">
                                                                <label class="col-md-3 control-label" for="secret-key">涨跌下界</label>
                                                                <div class="col-md-6">
                                                                    <input type="number" id="thld_end" name="thld_end" class="form-control buy_input" placeholder="" value="<#if args.thld_end??>${args.thld_end}<#else>0</#if>">
                                                                </div>
                                                                <label class="col-md-1 control-label base_symbol">%</label>
                                                            </div>
                                                        </form>
                                                    </div>
                                                    <div class="col-md-4">
                                                         <span>价格阀值范围内->不涨不跌；高于阀值->上涨；低于阀值->下跌</span>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                            <!-- END Form Validation Block -->
                        </div>
                    </div>
                <!----------吃单判定设置 -------------------->
                <div class="row">

                    <div class="col-md-12">
                        <!-- Form Validation Block -->
                        <div class="block">
                            <div class="block-title">
                                <h2>吃单判定设置</h2>
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                    <form id="form-set-api" method="post" class="form-horizontal form-bordered">
                                        <div class="form-group">
                                            <div class="row">
                                                <div class="col-md-8">
                                                    <form id="form-set-api" method="post" class="form-horizontal form-bordered">
                                                        <div class="form-group">
                                                            <label class="col-md-3 control-label" for="access-key">价格波动率阀值</label>
                                                            <div class="col-md-6">
                                                                <input type="number" id="price_change_rate_threshold" name="price_change_rate_threshold" class="form-control buy_input" placeholder="" value="<#if args.price_change_rate_threshold??>${args.price_change_rate_threshold}<#else>0</#if>">
                                                            </div>
                                                            <label class="col-md-1 control-label quote_symbol"></label>
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="col-md-3 control-label" for="secret-key">盘口收益率阀值</label>
                                                            <div class="col-md-6">
                                                                <input type="number" id="disk_yield_threshold" name="disk_yield_threshold" class="form-control buy_input" placeholder=""  value="<#if args.disk_yield_threshold??>${args.disk_yield_threshold}<#else>0</#if>">
                                                            </div>
                                                            <label class="col-md-1 control-label base_symbol">%</label>
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="col-md-3 control-label" for="secret-key">预期收益率阀值</label>
                                                            <div class="col-md-6">
                                                                <input type="number" id="expected_yield_threshold" name="expected_yield_threshold" class="form-control buy_input" placeholder=""  value="<#if args.expected_yield_threshold??>${args.expected_yield_threshold}<#else>0</#if>">
                                                            </div>
                                                            <label class="col-md-1 control-label base_symbol">%</label>
                                                        </div>



                                                    </form>
                                                </div>
                                                <div class="col-md-4">
                                                    <div class="form-group">
                                                        <span>价格波动率高于阀值时,吃单判定结果为否,即：系统不建议下单操作</span>
                                                    </div>
                                                    <div class="form-group">
                                                        <span>收益率=（卖出金额-买入金额-买入手续费-卖出手续费）/(买入金额+卖出金额)*100</span>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <!-- END Form Validation Block -->
                    </div>
                </div>
                <!----------量化交易设置 -------------------->
                <div class="row">
                    <div class="col-md-12">
                        <!-- Form Validation Block -->
                        <div class="block">
                            <div class="block-title">
                                <h2>量化交易设置</h2>
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                    <form id="form-set-api" method="post" class="form-horizontal form-bordered">
                                        <div class="form-group">
                                            <div class="row">
                                                <div class="col-md-8">
                                                    <form id="form-set-api" method="post" class="form-horizontal form-bordered">
                                                        <div class="form-group">
                                                            <div class="col-md-6">
                                                                <label class="col-md-3 control-label" for="val-skill">交易所</label>
                                                                <div class="col-md-6">
                                                                    <select id="select_exchange" name="api_exchange" class="form-control">
                                                                        <option value="">请选择</option>
                                                                    </select>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6">
                                                                <label class="col-md-3 control-label" for="val-skill">币对</label>
                                                                <div class="col-md-6">
                                                                    <select id="select_pair" name="api_exchange" class="form-control">
                                                                    </select>
                                                                </div>
                                                            </div>
                                                        </div>

                                                        <div class="form-group">
                                                            <label class="col-md-3 control-label" for="access-key">货币固定值</label>
                                                            <div class="col-md-6">
                                                                <input type="number" id="coin_stable_val" name="coin_stable_val" class="form-control buy_input" placeholder="">
                                                            </div>
                                                            <label class="col-md-1 control-label quote_symbol"></label>
                                                        </div>
                                                    </form>
                                                </div>
                                                <div class="col-md-4">
                                                    <span>当现有的币的个数, 大于货币固定值的180%或小于20% 系统会触发回流</span>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <!-- END Form Validation Block -->
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <!-- Form Validation Block -->
                        <div class="block">
                            <center><button type="button" id="btn_submit" class="btn btn-effect-ripple btn-primary center-block">保存</button></center>
                        </div>
                        <!-- END Form Validation Block -->
                    </div>
                </div>
            </div>
            <!-- END Page Container -->
        </div>
        <!-- END Page Wrapper -->

        <SCRIPT>
            $(function () {
                initExchange();
                <#--修改提交-->
                $("#btn_submit").click(function () {
                    //回购策略设置
                    var order_avg_price_threshold=$("input#order_avg_price_threshold").val()
                    //涨跌判定设置
                    var thld_start=$("input#thld_start").val()
                    var thld_end=$("input#thld_end").val()
                    //吃单判定设置
                    var price_change_rate_threshold=$("input#price_change_rate_threshold").val()
                    var disk_yield_threshold=$("input#disk_yield_threshold").val()
                    var expected_yield_threshold=$("input#expected_yield_threshold").val()
                    //货币固定值
                    var coin_stable_val=$("input#coin_stable_val").val()
                    var exchange_code=$("#select_exchange").val();
                    var en_coin_name=$("#select_pair").val();
                    args=[order_avg_price_threshold,thld_start,thld_end,price_change_rate_threshold,disk_yield_threshold,expected_yield_threshold];
                    if(validate(args)) {
                        var url = "/strategy_submit"
                        var args = {
                            "order_avg_price_threshold": order_avg_price_threshold,
                            "thld_start": thld_start,
                            "thld_end": thld_end,
                            "price_change_rate_threshold": price_change_rate_threshold,
                            "disk_yield_threshold": disk_yield_threshold,
                            "expected_yield_threshold": expected_yield_threshold,
                            "coin_stable_val": coin_stable_val,
                            "exchange_code": exchange_code,
                            "en_coin_name": en_coin_name
                        }
                        $.ajax({
                            url: url,
                            data: args,
                            cache: false,
                            type: "POST",
                            dataType: 'jsonp',
                            jsonp: "jsonpCallback",
                            //其中success_jsonpCallback为自定义名称，与后台保持一致即可
                            jsonpCallback: "success_jsonpCallback",
                            success: function (result) {
                                alert(result.msg)
                            }
                        });
                    }

                });
            });

            //其中一项不为0，通过
            function validate(args){
                for(var i=0;i<args.length;i++){
                    if(args[i]!=0){
                        return true;
                    }
                }
                return false;
            }
            function initExchange(){
                $.get("/exchange/list",function (data) {
                    var list=data.data;
                    var html="";
                    for (var i = 0; i <list.length; i++) {
                        html+="<option value="+list[i]+">"+list[i]+"</option>"
                    }
                    $("#select_exchange").append(html);
                });
            };


            $("#select_exchange").change(function () {
                var exchange=$("#select_exchange").val();
                initPairs(exchange);
            });

            $("#select_pair").change(function () {
                var exchange_code=$("#select_exchange").val();
                var en_coin_name=$("#select_pair").val();
                var url="/get_pair_stable_val"
                var args={"exchange_code":exchange_code,"en_coin_name":en_coin_name}
                $.ajax({
                    url: url,
                    data: args,
                    cache: false,
                    type: "GET",
                    dataType: 'jsonp',
                    jsonp: "jsonpCallback",
                    //其中success_jsonpCallback为自定义名称，与后台保持一致即可
                    jsonpCallback: "success_jsonpCallback",
                    success: function (result) {
                        if("200"==result.code) {
                            if(result.data==0){
                                $("input#coin_stable_val").val('');
                                return;
                            }
                            $("input#coin_stable_val").val(result.data);
                        }else{
                            alert(result.msg)
                        }
                    }
                });
            });

            function initPairs(exchange){
                $.get("/exchange/coins", null, function (data) {
                    $("#select_pair").empty();
                    var list=data.data;
                    var html="<option>请选择</option>";
                    for (var i = 0; i <list.length; i++) {
                        html+="<option value="+list[i]+">"+list[i]+"</option>"
                    }
                    $("#select_pair").append(html);
                });
            };


            $("#select_pair").change(function () {
                var pair=$("#select_pair").val().toUpperCase();
                var array=pair.split("_");
                var base=array[0];
                var quote=array[1];
            });

        </SCRIPT>
</body>

</html>